package com.thomasmoerman.dci3.tmc

import com.thomasmoerman.dci3.domain._
import com.thomasmoerman.dci3.frw._

trait TransferMoneyContextFactory {
  this: MoneySourceProvider with MoneySinkProvider =>  
  
  def newTransferMoneyContext = new TransferMoneyContext
  
  class TransferMoneyContext(
    var sourceAccount: Option[Account] = None, 
    var destinationAccount: Option[Account] = None, 
    var amount: Option[Double] = None) extends Context {
	  
	lazy val source: MoneySource = {
	  import MoneySourceConversion.convert
	  
	  sourceAccount getOrElse initError("No source account specified")
	}
	
	lazy val destination: MoneySink = {
	  import MoneySinkConversion.convert 
	  
	  destinationAccount getOrElse initError("No destination account specified")
	}
	
	lazy val money = amount getOrElse initError("No amount specified")
    
    def execute = source.transferMoney(destination, money)
    
  }
	
}